// store/index.js
import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
	state: {
		rongCloudConnected: false,
	},
	mutations: {
		setRongCloudConnected(state, connected) {
			state.rongCloudConnected = connected;
		},
	},
	actions: {
		connectRongCloud({
			commit
		}) {
			this._vm.$Request({
				method: 'POST',
				url: '/api/rong/getRongTo',
				data: {}
			}).then(res => {
				console.log(res, 111111111111111)
				if (res.code == 1) {
					this._vm.$RongIMLib.connect(res.data.token).then(res => {
						if (res.code === this._vm.$RongIMLib.ErrorCode.SUCCESS) {
							console.log('连接成功，用户ID为:', res.data.userId);
							commit('setRongCloudConnected', true);
						} else {
							console.warn('连接失败，code:', res.code);
						}
					});
				}
			})
		},
	},
});